//
//  YHJHomeViewController.m
//  Youhuiju
//
//  Created by yutenys on 16/7/13.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "YHJHomeViewController.h"

//跳转界面
#import "GoodsDetailViewController.h"//详情页
#import "CategoryViewController.h"//分类页
#import "CommunityViewController.h"//社区
#import "MessageViewController.h"//消息中心
#import "FreshProductViewController.h"//新品上市
#import "SpecialProductViewController.h"//特惠产品
#import "FreshHallViewController.h"//生鲜会馆

//#import "ViewOrderViewController.h"//我的订单
//#import "CountryViewController.h"//国家



#import "CollectViewController.h"//收藏

//自定义顶部
#import "TopNavagationBarView.h"//顶部视图
#import "SearchViewController.h"//自定义搜索框

//自定义cell
#import "AutoScrollViewTableViewCell.h"//顶上轮播图
#import "RecommendationsTableViewCell.h"//推荐菜单栏
#import "SpecialProductsTableViewCell.h"//特惠产品推荐
#import "FreshFoodTableViewCell.h"//生鲜惠馆(美妆会馆)
#import "ScrollTableViewCell.h"//滑动推荐
#import "PromotionTableViewCell.h"//暑假促销
#import "TwoImageTableViewCell.h"//推荐（两张图）
#import "YouLovedTableViewCell.h"//猜你喜欢

#import "YORequestHander.h"//网络请求
#import "goodModel.h"//商品数据模型

//刷新
#import <MJRefresh.h>


#import <AFNetworking.h>
#import "YORequestTools.h"

#import "UpdateView.h"

@interface YHJHomeViewController ()<UITableViewDelegate,UITableViewDataSource,SpecialCollectionViewClickedDelegate,FreshCollectionViewClickedDelegate,ScrollCollectionViewClickedDelegate,cellButtonClickedDelegate,cellClickedDelegate,UIGestureRecognizerDelegate>{
    BOOL isloadFished;
}

@property(nonatomic,strong)TopNavagationBarView *topNavagationBar;

@property(nonatomic,strong)UITableView *mainTableView;

@property(nonatomic,strong)UIButton *toTopButton;//回顶部

@property(nonatomic,strong)YORequestHander *requestHander;//网络请求
@property(nonatomic,strong)NSArray *dataArray;//数据


@property(nonatomic,strong)UpdateView *updateView;

@end

@implementation YHJHomeViewController

static NSString *autoScrollViewCellIden = @"autoScrollViewCellIden";//顶上轮播视图
static NSString *RecommendationsTableViewCellIden = @"RecommendationsTableViewCellIden";//推荐菜单栏
static NSString *SpecialProductsTableViewCellIden = @"SpecialProductsTableViewCellIden";//特惠产品推荐(母婴用品专区)
static NSString *FreshFoodTableViewCellIden = @"FreshFoodTableViewCellIden";//生鲜好惠馆(美妆会馆)
static NSString *ScrollTableViewCellIden = @"ScrollTableViewCellIden";//滚动产品
static NSString *PromotionTableViewCellIden = @"PromotionTableViewCellIden";//暑期促销
static NSString *TwoImageTableViewCellIden = @"TwoImageTableViewCellIden";//两张图推荐
static NSString *YouLovedTableViewCellIden = @"YouLovedTableViewCellIden";//猜你喜欢


static NSString *num1 = @"num1";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    [self load_UI];
    
    [self getData];
    
    
//    MJRefreshStateHeader *freshHeader = [MJRefreshStateHeader headerWithRefreshingTarget:self refreshingAction:@selector(pull)];
//    
//    MJRefreshGifHeader *freshGifHeader= [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(pull)];
//    
//    MJRefreshBackNormalFooter *freshFooter = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(up)];
//    
//    
//    NSMutableArray *array = [NSMutableArray array];
//    for (int i = 1; i<= 17; i++)
//    {
//        if (i < 10)
//        {
//            NSString *imagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"d0%zd",i] ofType:@"png"];
//            UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
//            [array addObject:appleImage];
//        }
//        else
//        {
//            NSString *imagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"d%zd",i] ofType:@"png"];
//            UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
//            [array addObject:appleImage];
//        }
//    }
//    
////    NSArray *arr = [NSArray arrayWithObjects:@"d01.png",@"d02.png",@"d03.png",@"d04.png",@"d05.png",@"d06.png",@"d07.png",@"d08.png",@"d09.png",@"d10.png",@"d11.png",@"d12.png",@"d13.png",@"d14.png",@"d15.png",@"d16.png",@"d17.png",nil];
//    DLog(@"%@",array);
//    NSArray *arr = [NSArray arrayWithArray:[array copy]];
//    DLog(@"%@",arr);
//
//    [freshGifHeader setImages:arr duration:2 forState:MJRefreshStateRefreshing];
//    [freshGifHeader setImages:arr duration:2 forState:MJRefreshStatePulling];
//    
//    [freshGifHeader setTitle:@"刷新中" forState:MJRefreshStateRefreshing];
//    
//    
////     [头setImages：_imagesArray时间：2 forState：MJRefreshStateRefreshing];
//    //设置动图
////    [freshGifHeader setImages:_imagesArray:2 forState:MJRefreshStateRefreshing];
//    //[包头setImages：_imagesArray时间：2 forState：MJRefreshStatePulling];
//    // [头setImages：_imagesArray时间：2 forState：       MJRefreshStateRefreshing];
//    
//    
//    self.mainTableView.mj_header = freshGifHeader;
//    self.mainTableView.mj_footer = freshFooter;
//    
//    //创建上拉加载控件类
//    // MJRefreshBackNormalFooter *页脚= [MJRefreshBackNormalFooter footerWithRefreshingTarget：自refreshingAction：@selector（footerRefresh）];
//    
////    MJRefreshBackNormalFooter *页脚= [MJRefreshBackNormalFooter footerWithRefreshingTarget:refreshingAction:@selector(MJRefreshFooter)]; //此种状态不能设置动图
//    
//    //设置动图
//    // [页脚setImages：_imagesArray时间：2 forState：MJRefreshStateRefreshing];
//    // [页脚setImages：_imagesArray时间：2 forState：MJRefreshStatePulling];
//    // [页脚setImages：_imagesArray时间：2 forState：MJRefreshStateRefreshing];
//    
////    _tableView.mj_footer =页脚;
//    
//    //马上进入刷新状态
//    // [头beginRefreshing]
//    
//    //是否根据拖拽比例自动切换透明度
////    freshHeader.automaticallyChangeAlpha = YES;
////    freshFooter.automaticallyChangeAlpha = YES;
//    
//    //是否隐藏时间
//    // header.lastUpdatedTimeLabel.hidden = NO;
//    //是否隐藏状态
//    // header.stateLabel.hidden = NO;
//    
//    //下拉自定义加载文字
////    [标题的setTitle：@“下拉刷新”forState：MJRefreshStateIdle];
////    [标题的setTitle：@“发布刷新”forState：MJRefreshStatePulling];
//    [freshHeader setTitle:@"载入中..."forState:MJRefreshStateRefreshing];
//    
////    //自定义字体
////    header.stateLabel.font = [UIFont systemFontOfSize：15];
////    header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize：14];
////    
////    //自定义颜色
////    header.stateLabel.textColor =的UIColor redColor]
////    header.lastUpdatedTimeLabel.textColor =的UIColor blueColor]
////    
//    //上拉自定义文字
//    // [页脚的setTitle：@“点击或拖动刷新”forState：MJRefreshStateIdle];
//    // [页脚的setTitle：@“正在加载更多...”forState：MJRefreshStateRefreshing];
//    [freshFooter setTitle:@"没有更多数据"forState:MJRefreshStateNoMoreData];
//    //
//    // //自定义字体
////    footer.stateLabel.font = [UIFont systemFontOfSize：17];
////    
////    //自定义颜色
////    footer.stateLabel.textColor =的UIColor redColor]
//    
//    //变为没有更多数据的状态
//    // [页脚endRefreshingWithNoMoreData]
//
//    
 }
//
//
//-(void)pull
//{
//    [_mainTableView reloadData];
//    [_mainTableView.mj_header endRefreshing];
//}
//-(void)up{
//
//    [_mainTableView reloadData];
//    [_mainTableView.mj_footer endRefreshing];
//}

#pragma mark ----- load_UI
/**
 *  加载视图
 */
-(void)load_UI
{
    
    [self getTestAPI];
    
    //获取设备UUID
    //1
//    NSString *uuidStr = [[NSUUID UUID]UUIDString];
    //2
    NSString *uuidStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    DLog(@"UUID:%@",uuidStr);
    
    //弹出更新提示
//    [self.updateView show];
    
    /**
     底部tableview
     */
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    _mainTableView.backgroundColor = [UIColor colorWithHexString:@"#ededed"];
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _mainTableView.showsVerticalScrollIndicator = NO;
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
    
    [_mainTableView registerClass:[AutoScrollViewTableViewCell class] forCellReuseIdentifier:autoScrollViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"RecommendationsTableViewCell" bundle:nil] forCellReuseIdentifier:RecommendationsTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"SpecialProductsTableViewCell" bundle:nil] forCellReuseIdentifier:SpecialProductsTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"FreshFoodTableViewCell" bundle:nil] forCellReuseIdentifier:FreshFoodTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"ScrollTableViewCell" bundle:nil] forCellReuseIdentifier:ScrollTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"PromotionTableViewCell" bundle:nil] forCellReuseIdentifier:PromotionTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"TwoImageTableViewCell" bundle:nil] forCellReuseIdentifier:TwoImageTableViewCellIden];
    [_mainTableView registerNib:[UINib nibWithNibName:@"YouLovedTableViewCell" bundle:nil] forCellReuseIdentifier:YouLovedTableViewCellIden];
    
    [_mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topNavagationBar.mas_bottom);
//        make.top.equalTo(self.view.mas_top).offset(64);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom).offset(- 49);
    }];
    
    _mainTableView.tableFooterView = [[UITableView alloc]init];
    
    [self topNavagationBar];
    
    //整个界面滑动转场
//    UISwipeGestureRecognizer *jumpGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(jumpViewController:)];
//    jumpGesture.delegate = self;
//    [jumpGesture setDirection:UISwipeGestureRecognizerDirectionLeft];
//    _mainTableView.userInteractionEnabled = YES;
//    [_mainTableView addGestureRecognizer:jumpGesture];
    
    
    _toTopButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _toTopButton.backgroundColor = [UIColor clearColor];
    [_toTopButton setBackgroundImage:LoadImage(@"toTop") forState:UIControlStateNormal];
    [_toTopButton addTarget:self action:@selector(toTopAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_toTopButton];
    [_toTopButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-20 * FitW);
        make.bottom.equalTo(self.view.mas_bottom).offset(-100 * FitH);
        make.size.mas_equalTo(CGSizeMake(40 * FitW, 40 * FitH));
    }];
//    _toTopButton.hidden = YES;
    _toTopButton.alpha = 0;
    
    
}
#pragma mark -------- test ----------


-(void)getTestAPI
{
    
//   NSString *url = @"getAllAddress";

    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:@"sku" forKey:@"66666"];
//    NSDictionary *param = @{@"sku":@"66666"};
    
    NSString *url = @"index";
    
    [YORequestTools requestDataWithAPIName:url Params:nil success:^(NSURLSessionDataTask *task, id responeObject) {

        DLog(@"请求成功~~~~~~~~~~~~response:%@",responeObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        DLog(@"请求失败~~~~~~~~~~~~error:%@",error);
    }];
    
    
    
//    NSString *ur =  @"http://192.168.1.23:8080/lightSmart-rest/mobile/index.do";

  }

#pragma mark ----- getData
-(void)getData
{
//    [self.requestHander getWithAPIName:HomePageAPI apiVersion:nil parameters:nil cachIdentifier:nil success:^(id response) {
////        DLog(@"网络请求成功--------\n%@",response);
//        NSArray *models = response[@"C001"][@"C001TypeThree"];
////        DLog(@"%@",[models.lastObject objectForKey:@"pudName"]);
//        self.dataArray = [[MTLJSONAdapter modelsOfClass:[GoodModel class] fromJSONArray:models error:nil] mutableCopy];
//        DLog(@"%@",self.dataArray.lastObject);
//        [self.mainTableView reloadData];
//    } failure:^(NSString *errorMessage) {
//        DLog(@"请求失败");
//    }];
}


#pragma mark ----------Tableview delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 8;//暂时取消母婴的滑动collectionView
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }
    else
    {
    return 0 * FitH;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 2;
    }
    else
    {
        return 1;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section)
    {
        case 0:
            if (indexPath.row == 0)
            {
                return 159 * FitH + 44;//轮播图
            }
            else
            {
                return 105 * FitH;//推荐菜单栏
            }
            break;
        case 1:
            return 346 * FitH;//美妆会馆
            break;
        case 2:
            return 239 * FitH;
            break;
//        case 3: //--------暂时取消掉母婴滑动collectionView
//            return 135 * FitH;
//            break;
        case 3:
            return 346 * FitH;
            break;
        case 4:
            return 105 * FitH;
            break;
        case 5:
            return 231 * FitH;
            break;
        case 6:
            return 95 * FitH;
            break;
        case 7:
            return 438 * FitH;
            break;
            
        default:
            return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *imgUrlArr = @[@"meizhuang",@"muying",@"shengxian",@"bangong",@"youloved"];
    WeakObj(self);
    switch (indexPath.section)
    {
        case 0://顶部轮播图和推荐菜单栏分区
        {
            if (indexPath.row == 0)//顶上轮播图
            {
                
                AutoScrollViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:autoScrollViewCellIden];
                NSDictionary *di = [NSDictionary dictionary];
                [cell getImagesByPara:di];
                
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
                
            }
            else//推荐菜单栏
            {
                RecommendationsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RecommendationsTableViewCellIden];
                cell.clickButtonHandler = ^(NSInteger buttonTag){
                
                    switch (buttonTag) {
                        case 0:
                        {
                            FreshProductViewController  *FVC = [[FreshProductViewController alloc]initWithNibName:@"FreshProductViewController" bundle:nil];
                            FVC.titleString = @"新品上市";
                            weakself.hidesBottomBarWhenPushed = YES;
                            [weakself.navigationController pushViewController:FVC animated:YES];
                            weakself.hidesBottomBarWhenPushed = NO;
                        }
                            DLog(@"新品上市");
                            break;
                        case 1:
                        {
                            SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                            SVC.dataString = @"全球好货";
                            weakself.hidesBottomBarWhenPushed = YES;
                            [weakself.navigationController pushViewController:SVC animated:YES];
                            weakself.hidesBottomBarWhenPushed = NO;
                        }
                            DLog(@"全球好货");
                            break;
                        case 2:
                        {
                            SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                            SVC.dataString = @"特惠产品";
                            weakself.hidesBottomBarWhenPushed = YES;
                            [weakself.navigationController pushViewController:SVC animated:YES];
                            weakself.hidesBottomBarWhenPushed = NO;
                        }
                            DLog(@"特惠产品");
                            break;
                        case 3:
                        {
                            CommunityViewController  *CVC = [[CommunityViewController alloc]initWithNibName:@"CommunityViewController" bundle:nil];
//                            CollectViewController *CVC = [[CollectViewController alloc]initWithNibName:@"CollectViewController" bundle:nil];
                            weakself.hidesBottomBarWhenPushed = YES;
                            [weakself.navigationController pushViewController:CVC animated:YES];
                            weakself.hidesBottomBarWhenPushed = NO;
                        }
                            DLog(@"社区");
                            break;
                            
                        default:
                            break;
                    }
                    
                };
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
            
        }
            break;
        case 1://美妆会馆
        {
            SpecialProductsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SpecialProductsTableViewCellIden];
            cell.clickedCellJumpDelegate = self;
            cell.dataSource = self.dataArray;
            cell.imgUrl = imgUrlArr[indexPath.section - 1];
            cell.moreBtnClickHandler = ^{
                
                SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                SVC.dataString = @"美妆会馆";
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:SVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"查看更多");
            };
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }
            break;
        case 2://母婴
        {
            FreshFoodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FreshFoodTableViewCellIden];
            cell.clickedCellJumpDelegate = self;
            cell.imgUrl = imgUrlArr[indexPath.section - 1];
            cell.moreBtnClickHandler = ^{
                SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                SVC.dataString = @"母婴用品";
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:SVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"查看更多");
            };
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }
            break;
//        case 3://滑动广告推荐 ------------ 暂时取消掉
//        {
//            ScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScrollTableViewCellIden];
//            cell.clickedCellJumpDelegate = self;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }
//            break;
        case 3://生鲜
        {
            SpecialProductsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SpecialProductsTableViewCellIden];
            cell.SpeView.hidden = YES;
            cell.clickedCellJumpDelegate = self;
            cell.dataSource = self.dataArray;//-----------替换数据，，暂时为美妆数据
            cell.imgUrl = imgUrlArr[indexPath.section - 1];
            cell.moreBtnClickHandler = ^{
                FreshHallViewController  *FVC = [[FreshHallViewController alloc]initWithNibName:@"FreshHallViewController" bundle:nil];
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:FVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"查看更多");
            };
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
            break;
        case 4://暑期大促
        {
            PromotionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PromotionTableViewCellIden];
            cell.buttonClickHandler = ^{
                
                GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:DVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"暑假大促");
            };
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
            break;
        case 5://办公用品
        {
            FreshFoodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FreshFoodTableViewCellIden];
            cell.imgUrl = imgUrlArr[indexPath.section - 2];
            cell.moreBtnClickHandler = ^{
                SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                SVC.dataString = @"办公用品";
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:SVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"查看更多");            };
            cell.clickedCellJumpDelegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
            break;
        case 6://两张图产品推荐
        {
            TwoImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TwoImageTableViewCellIden];
            cell.ImgClickedHandler = ^(NSInteger buttonTag){
                if (buttonTag == 0)
                {
                    GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
                    weakself.hidesBottomBarWhenPushed = YES;
                    [weakself.navigationController pushViewController:DVC animated:YES];
                    weakself.hidesBottomBarWhenPushed = NO;
                    DLog(@"这是第一张图");
                }
                else
                {
                    GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
                    weakself.hidesBottomBarWhenPushed = YES;
                    [weakself.navigationController pushViewController:DVC animated:YES];
                    weakself.hidesBottomBarWhenPushed = NO;
                    DLog(@"这是第二张图");
                }

            };
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
            break;
        case 7://猜你喜欢
        {
            YouLovedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:YouLovedTableViewCellIden];
            cell.cellButtonDelegate = self;
            cell.cellDelegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.imgUrl = imgUrlArr[indexPath.section - 3];
            cell.moreButtonClickedHandler = ^{
            
                SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
                SVC.dataString = @"猜你喜欢";
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:SVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
                DLog(@"查看更多");
            };
            
            return cell;
        }
            break;
            
        default:
            return nil;
    }
    
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    WeakObj(self);
    CGFloat sectionHeaderHeight = 10 * FitH;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
    
    if (scrollView.contentOffset.y > 700 * FitH)
    {
//        self.toTopButton.hidden = NO;
        [UIView animateWithDuration:1 animations:^{
            
            weakself.toTopButton.alpha = 1;
        }];
        
    }
    else
    {
        [UIView animateWithDuration:1 animations:^{
            
            weakself.toTopButton.alpha = 0;
        }];

    }
  
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ------Private delegate
/**
 *  美妆，生鲜点击跳转协议
 */
-(void)specialClickedCellJump:(NSString *)jumpAPI
{
    DLog(@"跳转啦~~~~~~~~~~~~~~~~~~~~~~");
//    if (self.dataArray != nil) {
    
        GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
        DVC.goodDetailAPI = jumpAPI;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:DVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
//    }
//    else
//    {
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"哎呀~网络好像开小差了！" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//        
//        [alert show];
//    }
}
/**
 *  母婴，办公点击跳转协议
 */
-(void)freshClickedCellJump
{
//    if (self.dataArray != nil)
//    {
    
        GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:DVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
//    }
//    else
//    {
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"哎呀~网络好像开小差了！" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//        
//        [alert show];
//    }
}
/**
 *  滑动广告点击跳转协议
 */
//-(void)scrollClickedCellJump
//{
//    GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
//    self.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:DVC animated:YES];
//    self.hidesBottomBarWhenPushed = NO;
//}

//猜你喜欢按钮点击协议
-(void)cellButtonClickedJump:(NSInteger)btnTag :(NSString *)categoryStr
{
    if (btnTag == 0)
    {
//        GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
//        self.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:DVC animated:YES];
//        self.hidesBottomBarWhenPushed = NO;
        DLog(@"这是加入购物车button");
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"已添加购物车" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
        [alert show];
    }
    else
    {
        SpecialProductViewController  *SVC = [[SpecialProductViewController alloc]initWithNibName:@"SpecialProductViewController" bundle:nil];
        SVC.dataString = categoryStr;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:SVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        DLog(@"这是进入分类button");
    }
}

//猜你喜欢cell点击协议
-(void)cellClickedJump
{
    DLog(@"你点击了cell");
    GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:DVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

#pragma mark ---- gesture

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer
{
    if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]])
    {
        return NO;
    }
    return YES;
}
-(void)jumpViewController:(UISwipeGestureRecognizer *)gesture
{

    DLog(@"左滑了~~~~~~~~~~~");
//    CountryViewController *cvc = [[CountryViewController alloc]initWithNibName:@"CountryViewController" bundle:nil];
//    CATransition *animation = [CATransition animation];
//    animation.delegate = self;
//    animation.fillMode = @"oglFlip";
//    animation.type = kCAGravityLeft;
//    [self.navigationController.view.layer addAnimation:animation forKey:nil];
//    [self.navigationController pushViewController:cvc animated:YES];
    
    
//CountryViewController *cvc = [[CountryViewController alloc]initWithNibName:@"CountryViewController" bundle:nil];        [self.navigationController pushViewController:cvc animated:NO];
//        //因为一个事件循环机制中
//        CATransition *tran=[CATransition animation];
//        tran.duration = 0.75;
//        tran.type=@"oglFlip";
//        tran.subtype=kCATransitionFromLeft;
//    self.hidesBottomBarWhenPushed = YES;
//        [self.navigationController.view.layer addAnimation:tran forKey:nil];
//    self.hidesBottomBarWhenPushed = NO;
    
    
    
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:0.5];
//    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view  cache:YES];
// CountryViewController *cvc = [[CountryViewController alloc]initWithNibName:@"CountryViewController" bundle:nil];
//    
//    self.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:cvc animated:NO];
//    self.hidesBottomBarWhenPushed = NO;
//    [UIView commitAnimations];
//    
}





-(void)toTopAction:(UIButton *)sender
{
    DLog(@"回顶部");
    [self.mainTableView setContentOffset:CGPointMake(0, 0) animated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

-(void)viewWillDisappear:(BOOL)animated

{
    [super viewWillDisappear:animated];
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    
}

#pragma mark ------lazy loading

-(TopNavagationBarView *)topNavagationBar
{
    if (!_topNavagationBar) {
        _topNavagationBar = [[TopNavagationBarView alloc]init];
        _topNavagationBar.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_topNavagationBar];
        [_topNavagationBar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top).offset(20 );
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            make.height.mas_offset(44 );
        }];
        WeakObj(self);
        _topNavagationBar.searchHandler = ^(NSInteger buttonTag){
            if (buttonTag == 0)
            {
                DLog(@"搜索商品");
                SearchViewController *svc = [[SearchViewController alloc]init];
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:svc animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
            }
            else if(buttonTag == 1)
            {
                MessageViewController *svc = [[MessageViewController alloc]initWithNibName:@"MessageViewController" bundle:nil];
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:svc animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
            }
            else{
                CategoryViewController  *DVC = [[CategoryViewController alloc]initWithNibName:@"CategoryViewController" bundle:nil];
                weakself.hidesBottomBarWhenPushed = YES;
                [weakself.navigationController pushViewController:DVC animated:YES];
                weakself.hidesBottomBarWhenPushed = NO;
            }
        };
    }
    return _topNavagationBar;
}

- (YORequestHander *)requestHander
{
    //    WeakObj(self);
    if (!_requestHander) {
        _requestHander = [YORequestHander shareInstance];
        //        _requestHandler.netWorkNotReachableHandler = ^(){
        //            DLog(@"当前网络不可用");
        //            [weakself.noNetworkView show];
        //        };
    }
    return _requestHander;
}

- (UpdateView *)updateView
{
    if (!_updateView) {
        _updateView = [[UpdateView alloc] initWithFrame:CGRectMake(0, 0, 235 * FitW, 391*FitH)];
        _updateView.center = self.view.center;
//        _updateView.backgroundColor = [UIColor whiteColor];
        //        _updateView = [[UpdateView alloc]init];
    }
    return _updateView;
}


@end
